#!/bin/tcsh
#
#  This script runs NWChem on mnemosyne
#
module load mpich
module load nwchem/6.5
#
setenv NWCHEM_PROCS 4
setenv NWCHEM_MEMORY "1200 mb"
setenv NWCHEM_SCRATCH /home/mark/nwchem/scratch
#
set procid=`echo $$`
setenv JOBNAME `ps -p $procid | grep $procid | awk '{print $4}'`
setenv NWCHEM_ROOT `echo $JOBNAME | awk -F_ '{print $1}'`
setenv NWCHEM_SUFFIX `echo $JOBNAME | awk -F_ '{print $2}'`
mkdir $NWCHEM_SCRATCH/$procid
#
# Build the input file
#
cat << finis > $JOBNAME.nw
title "water optimization"

start  $NWCHEM_ROOT
permanent_dir $cwd
scratch_dir $NWCHEM_SCRATCH/$procid
memory $NWCHEM_MEMORY
print low
ecce_print $JOBNAME.ecce

charge 0

geometry  autosym units angstrom
  zmatrix
     O1       
     H1     O1    dwoh
     H2     O1    dwoh    H1  awoh
     H3     O1    doh     H1  aoh       H2   poh
     X2     H3    one     O1  ninety    H1   zero
     O2     H3    dwoh    X2  ninety    O1   pi
     H4     O2    dwoh    H3  awoh      X2   pi
  variables
    doh     2.7
    aoh    109.5
  constants
    poh   125.25
    dwoh    0.96528
    awoh    105.72566
    one     1.
    ninety  90.
    zero    0.
    pi      180.
  end
end

basis 
  * library "6-31++G**"
end

dft
  xc b3lyp
  iterations 1000
  direct
  noio
end


task dft optimize

dplot
  vectors $NWCHEM_ROOT.movecs
  limitxyz units angstrom
  -3.0  3.0  100
  -3.0  3.0  100
  -3.0  3.0  100
  spin total
  where g+n
  gaussian
  output $NWCHEM_ROOT.cube
end

task dplot
finis
#
#   Run the job
#
mpirun -np $NWCHEM_PROCS nwchem $JOBNAME.nw >& $JOBNAME.nwo
#
#   Clean up scratch directory
rm -rf $NWCHEM_SCRATCH/$procid
